using FW;
using UnityEngine;

public class WeaponManager : MonoBehaviour
{
    public Player Owner;
    public WeaponInfo LeftWeaponEntity;
    public WeaponInfo RightWeaponEntity;

    public void Awake()
    {
        Owner = GetComponentInParent<Player>();
        var LeftWeapon = GameObject.FindWithTag("LeftWeapon").transform.GetChild(0).gameObject;
        LeftWeaponEntity = new WeaponInfo(LeftWeapon);
        var RightWeapon = GameObject.FindWithTag("RightWeapon").transform.GetChild(0).gameObject;
        RightWeaponEntity = new WeaponInfo(RightWeapon);


    }
    public void WeaponEnable()
    {
        SetWeaponEngine(Owner.keyInput.leftAttack, true);
    }

    public void WeaponDisable()
    {
        SetWeaponEngine(Owner.keyInput.leftAttack, false);
    }

    public void SetWeaponEngine(bool isLeft,bool isEnable)
    {
        if (isLeft)
            LeftWeaponEntity.EnableWeapon(isEnable);
        else 
            RightWeaponEntity.EnableWeapon(isEnable);
    }

}


//对接excel表 美术mesh 以及collider
public class WeaponInfo
{
    public Collider Collider;
    public int WeaponID;
    public WeaponInfo(int WeaponID, BoxCollider boxCollider)
    {
        this.Collider = boxCollider;
        this.WeaponID = WeaponID;
    }

    public WeaponInfo(GameObject Weapon)
    {
        this.Collider = Weapon.GetComponent<Collider>();
    }
    public void EnableWeapon(bool isEnable)
    {
        Collider.enabled = isEnable;
    }

}
